package com.example.code.class01;

/**
 * @Date 2022/7/11
 * @Created by Jonathan
 */
public class Code3_Near2Power {
    public static void main(String[] args) {
        int cap = 120;
        System.out.println(tableSizeFor(cap));
    }


    public static int tableSizeFor(int n) {
        n--;  // 这个是兼容本来就是2的整数次幂的情况
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return n < 0 ? 1 : n + 1;
    }
}
